﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Eleanor.Website.Utility;
using System.Dynamic;
using Eleanor.BLL;

namespace Eleanor.Website.Controllers
{
    public class AccountController : EleanorControllerBase
    {
        public SubscriberBLL subscriberBLL = new SubscriberBLL();

        public ActionResult Subscribe()
        {
            return View();
        }

        public ActionResult DoSubscribe()
        {
            dynamic result = new ExpandoObject();
            result.Status = true;
            string email = Request.Form["email"];
            dynamic subscriber = subscriberBLL.Get(email);
            if (subscriber == null)
            {
                subscriber = new ExpandoObject();
                subscriber.Email = email;
                subscriber.Name = Request.Form["name"];
                subscriber.Telephone = Request.Form["phone"];
                subscriber.CreateDate = DateTime.Now;
                subscriberBLL.Add(subscriber);
            }
            else
            {
                subscriber.Name = Request.Form["name"];
                subscriber.Telephone = Request.Form["phone"];
                subscriber.UpdateDate = DateTime.Now;
                subscriberBLL.Update(subscriber);
            }            
            return Json(result);
        }

    }
}
